<template>
	<view class="login-container">
		<uni-icons type="contact-filled" size="100" color="#afafaf"></uni-icons>
		<button type="primary" class="btn-login" open-type="getUserInfo" @getuserinfo="getUserInfo">一键登录</button>
		<text class="tips-text" >点击以上按钮登录</text>
	
	</view>	
</template>
<script>
	export default{
		data(){
			return{
				user:{
					user_img:'',
					user_name:''
				}
				
				
				
			};
		},
		methods:{
			
	
			getUserInfo(e){
				if(e.detail.errMsg==='getUserInfo:fail auth deny') return uni.$showMsg('您取消了登录授权')
			this.getToken(e.detail)
		},
		async getToken(info){
			const[err,res]=await uni.login().catch(err =>err)
			
			if(res.errMsg !=='login:ok') return uni.$showMsg('登录失败')
			
			this.user.user_img=info.userInfo.avatarUrl
			this.user.user_name=info.userInfo.nickName
			
			this.$emit('click',this.user)
		},
		
	}
	
	}
</script>
<style lang="scss">
	.login-container{
		height: 750rpx;
		background-color: #f8f8f8;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		
		.btn-login{
			width: 90%;
			border-radius: 100px;
			margin: 15px 0;
			background-color: #c00000;
		}
		.tips-text{
			font-size: 12px;
			color: gray;
		}
	}
</style>
